package com.example.big_event.Utils;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

// 用户返回共同的响应对象
//统一响应结果
@AllArgsConstructor
@NoArgsConstructor
@Data
public class Result<T> {
    private Integer code; //业务状态码 0-成功 1-失败
    private String message; //提示信息
    private T data; //响应数据

    //快速返回操作成功响应结果(带响应数据)
    public static <E> Result<E> success(E data) {

        Result<E> result =new Result<E>();
        result.code = 0;
        result.message = "操作成功";
        result.data = data;

        return result;
    }

    //快速返回操作成功响应结果,有些操作成功之后不需要响应数据
    public static<E>  Result<E>  success() {
        Result<E> result =new Result<E>();
        result.code = 0;
        result.message = "操作成功";
        result.data = null;

        return result;
    }

    // 用于处理错误信息
    public static<E>  Result<E>  error(String message) {
        Result<E> result =new Result<E>();
        result.code = 1;
        result.message = message;
        result.data = null;
        return result;
    }
}
